//package com.sch.www.sys.configuration;
//
//import com.alibaba.fastjson.parser.ParserConfig;
//import com.alibaba.fastjson.serializer.SerializerFeature;
//import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
//import com.sch.www.common.springCache.CustomCacheKeyGenerator;
//import org.springframework.boot.autoconfigure.cache.CacheProperties;
//import org.springframework.cache.CacheManager;
//import org.springframework.cache.annotation.CachingConfigurer;
//import org.springframework.cache.annotation.EnableCaching;
//import org.springframework.cache.interceptor.CacheErrorHandler;
//import org.springframework.cache.interceptor.CacheResolver;
//import org.springframework.cache.interceptor.KeyGenerator;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.cache.RedisCacheConfiguration;
//import org.springframework.data.redis.serializer.RedisSerializationContext;
//
//
//@EnableCaching
//@Configuration
//public class SpringRedisCacheConfiguration {
//    /**
//     * redis 序列化使用FastJson
//     *
//     * @param cacheProperties
//     * @return
//     */
//    @Bean
//    public RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties) {
//        FastJsonRedisSerializer serializer = new FastJsonRedisSerializer(Object.class);
//        //fastJson序列化时加入对象的类名。
//        serializer.getFastJsonConfig().setSerializerFeatures(SerializerFeature.WriteClassName);
//        //类名加入了json中在反序列化时须开启AutoType。参考： https://github.com/alibaba/fastjson/wiki/enable_autotype
//        ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
//
//        CacheProperties.Redis redisProperties = cacheProperties.getRedis();
//        RedisCacheConfiguration config = RedisCacheConfiguration
//                .defaultCacheConfig();
//        config = config.serializeValuesWith(RedisSerializationContext.SerializationPair
//                .fromSerializer(serializer));
//        if (redisProperties.getTimeToLive() != null) {
//            config = config.entryTtl(redisProperties.getTimeToLive());
//        }
//        if (redisProperties.getKeyPrefix() != null) {
//            config = config.prefixKeysWith(redisProperties.getKeyPrefix());
//        }
//        if (!redisProperties.isCacheNullValues()) {
//            config = config.disableCachingNullValues();
//        }
//        if (!redisProperties.isUseKeyPrefix()) {
//            config = config.disableKeyPrefix();
//        }
//        return config;
//    }
//
//
//    /**
//     *  修改SpringCache的默认配置。
//     * @return
//     */
//    @Bean
//    public CachingConfigurer cachingConfigurer() {
//        return new CachingConfigurer() {
//            @Override
//            public KeyGenerator keyGenerator() {
//                //使用自定义的CustomCacheKeyGenerator替代默认的SimpleKeyGenerator。
//                return new CustomCacheKeyGenerator();
//            }
//            @Override
//            public CacheManager cacheManager() {
//                return null;
//            }
//            @Override
//            public CacheResolver cacheResolver() {
//                return null;
//            }
//
//            @Override
//            public CacheErrorHandler errorHandler() {
//                return null;
//            }
//        };
//    }
//}
